#include <stdio.h>
#include "slist.h"
#include <stdlib.h>

int my_print(void *data);
int my_destroy(void *data);


int main(int argc, char **argv)
{
#ifdef DEBUG
    printf("hello world\n");
#endif 
    slist_t *s = NULL;
    int num = 0;

    slist_create(&s, sizeof(int), my_destroy);

    while (1)
    {
    op:
        my_scanf(op, "%d", &num);

        if (num == -1)
        {
            break;
        }

        slist_append(s, &num);
    }

    slist_traverse(s, my_print);

    slist_destroy(s);


    return 0;
}

int my_print(void *data)
{
    /* 变量定义 */
    node_t *tmp = NULL;

    /* 参数检查 */
    if (NULL == data)
    {   
        perror("argument lawless...");
        goto err0;
    } /* end of if (NULL == data) */

    /* 打印节点 */
    tmp = data;
    printf("%d ", *(int *)(tmp->data));



    return 0;
err0:
    return -1;
}

int my_destroy(void *data)
{
    /* 变量定义 */
    node_t *tmp = NULL;

    /* 参数检查 */
    if (NULL == data)
    {
        perror("argument lawless...");
        goto err0;
    } /* end of if (NULL == data) */

    /* 销毁节点 */
    tmp = data;

    free(tmp->data);
    tmp->data = NULL;
    free(tmp);
    tmp = NULL;


    return 0;
err0:
    return -1;
}